home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / device-stream.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-07  |  6.6 KB  |  291 lines

  1. /* Stream device functions.
  2.    Copyright (C) 1995 Amdahl Corporation
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: Not in FSF. */
  21.  
  22. /* This file has been Mule-ized. */
  23.  
  24. /* Written by Ben Wing. */
  25.  
  26. #include <config.h>
  27. #include "lisp.h"
  28.  
  29. #include "device-stream.h"
  30. #include "events.h"
  31. #include "frame.h"
  32. #include "redisplay.h"
  33. #include "sysdep.h"
  34.  
  35. DEFINE_DEVICE_TYPE (stream);
  36.  
  37. Lisp_Object Vterminal_device;
  38. Lisp_Object Vterminal_frame;
  39.  
  40. static void
  41. allocate_stream_device_struct (struct device *d)
  42. {
  43.   d->device_data =
  44.     (struct stream_device *) xmalloc (sizeof (struct stream_device));
  45.  
  46.   /* zero out all slots. */
  47.   memset (d->device_data, 0, sizeof (struct stream_device));
  48. }
  49.  
  50. static void
  51. stream_init_device (struct device *d, Lisp_Object device_data)
  52. {
  53.   Lisp_Object tty = Qnil;
  54.   FILE *infd, *outfd, *errfd;
  55.  
  56.   tty = Fnth (Qzero, device_data);
  57.  
  58.   /* Open the specified device */
  59.  
  60.   if (NILP (tty))
  61.     {
  62.       infd = stdin;
  63.       outfd = stdout;
  64.       errfd = stderr;
  65.     }
  66.   else
  67.     {
  68.       CHECK_STRING (tty, 0);
  69.       infd = outfd = errfd =
  70.     fopen ((char *) string_data (XSTRING (tty)), "r+");
  71.       if (!infd)
  72.     error ("Unable to open tty %s", string_data (XSTRING (tty)));
  73.     }
  74.  
  75.   allocate_stream_device_struct (d);
  76.   DEVICE_STREAM_DATA (d)->infd = infd;
  77.   DEVICE_STREAM_DATA (d)->outfd = outfd;
  78.   DEVICE_STREAM_DATA (d)->errfd = errfd;
  79.   DEVICE_INFD (d) = fileno (infd);
  80.   DEVICE_OUTFD (d) = fileno (outfd);
  81.   init_baud_rate (d);
  82.   init_one_device (d);
  83. }
  84.  
  85. static int
  86. stream_initially_selected_for_input (struct device *d)
  87. {
  88.   return noninteractive && initialized;
  89. }
  90.  
  91. static void
  92. free_stream_device_struct (struct device *d)
  93. {
  94.   struct stream_device *td = (struct stream_device *) d->device_data;
  95.   if (td)
  96.     xfree (td);
  97. }
  98.  
  99. extern int stdout_needs_newline;
  100.  
  101. static void
  102. stream_delete_device (struct device *d)
  103. {
  104.   if (/* DEVICE_STREAM_DATA (d)->needs_newline */
  105.       stdout_needs_newline) /* #### clean this up */    
  106.     {
  107.       fputc ('\n', DEVICE_STREAM_DATA (d)->outfd);
  108.       fflush (DEVICE_STREAM_DATA (d)->outfd);
  109.     }
  110.   if (DEVICE_STREAM_DATA (d)->infd != stdin)
  111.     fclose (DEVICE_STREAM_DATA (d)->infd);
  112.   free_stream_device_struct (d);
  113. }
  114.  
  115.  
  116. static void
  117. stream_init_frame (struct frame *f, Lisp_Object parms)
  118. {
  119.   struct device *d = XDEVICE (FRAME_DEVICE (f));
  120.   if (!NILP (DEVICE_FRAME_LIST (d)))
  121.     error ("Only one frame allowed on stream devices");
  122.  
  123.   f->name = build_string ("stream");
  124.   f->height = 80;
  125.   f->width = 24;
  126.   f->visible = 0; /* so redisplay doesn't try to do anything */
  127. }
  128.  
  129.  
  130. static void
  131. stream_font_metric_info (struct device *d, Lisp_Object font,
  132.              struct font_metric_info *fm)
  133. {
  134.   fm->width = 1;
  135.   fm->height = 1;
  136.   fm->ascent = 1;
  137.   fm->descent = 0;
  138.   fm->proportional = 0;
  139. }
  140.  
  141. static int
  142. stream_text_width (struct window *w, Lisp_Object font,
  143.            CONST Emchar *s, int len)
  144. {
  145.   return len;
  146. }
  147.  
  148. static int
  149. stream_left_margin_width (struct window *w)
  150. {
  151.   return 0;
  152. }
  153.  
  154. static int
  155. stream_right_margin_width (struct window *w)
  156. {
  157.   return 0;
  158. }
  159.  
  160. static int
  161. stream_divider_width (void)
  162. {
  163.   return 1;
  164. }
  165.  
  166. static int
  167. stream_divider_height (void)
  168. {
  169.   return 1;
  170. }
  171.  
  172. static int
  173. stream_eol_cursor_width (void)
  174. {
  175.   return 1;
  176. }
  177.  
  178. static void
  179. stream_output_begin (struct device *d)
  180. {
  181. }
  182.  
  183. static void
  184. stream_output_end (struct device *d)
  185. {
  186. }
  187.  
  188. static void
  189. stream_output_display_block (struct window *w, struct display_line *dl,
  190.                  int block, int start, int end,
  191.                  int start_pixpos, int cursor_start,
  192.                  int cursor_width, int cursor_height)
  193. {
  194. }
  195.  
  196. static void
  197. stream_output_vertical_divider (struct window *w, int clear)
  198. {
  199. }
  200.  
  201. static void
  202. stream_clear_to_window_end (struct window *w, int ypos1, int ypos2)
  203. {
  204. }
  205.  
  206. static void
  207. stream_clear_region (Lisp_Object locale, face_index findex, int x, int y,
  208.                int width, int height)
  209. {
  210. }
  211.  
  212. static void
  213. stream_clear_frame (struct frame *f)
  214. {
  215. }
  216.  
  217. static int
  218. stream_flash (struct device *d)
  219. {
  220.   return 0; /* sorry can't do it */
  221. }
  222.  
  223. static void
  224. stream_ring_bell (struct device *d, int volume, int pitch, int duration)
  225. {
  226.   fputc (07, DEVICE_STREAM_DATA (d)->outfd);
  227.   fflush (DEVICE_STREAM_DATA (d)->outfd);
  228. }
  229.  
  230.  
  231. /************************************************************************/
  232. /*                            initialization                            */
  233. /************************************************************************/
  234.  
  235. void
  236. device_type_create_stream (void)
  237. {
  238.   INITIALIZE_DEVICE_TYPE (stream, "stream", "device-stream-p");
  239.  
  240.   /* device methods */
  241.   DEVICE_HAS_METHOD (stream, init_device);
  242.   DEVICE_HAS_METHOD (stream, initially_selected_for_input);
  243.   DEVICE_HAS_METHOD (stream, delete_device);
  244.  
  245.   /* frame methods */
  246.   DEVICE_HAS_METHOD (stream, init_frame);
  247.  
  248.   /* redisplay methods */
  249.   DEVICE_HAS_METHOD (stream, left_margin_width);
  250.   DEVICE_HAS_METHOD (stream, right_margin_width);
  251.   DEVICE_HAS_METHOD (stream, text_width);
  252.   DEVICE_HAS_METHOD (stream, font_metric_info);
  253.   DEVICE_HAS_METHOD (stream, output_display_block);
  254.   DEVICE_HAS_METHOD (stream, output_vertical_divider);
  255.   DEVICE_HAS_METHOD (stream, divider_width);
  256.   DEVICE_HAS_METHOD (stream, divider_height);
  257.   DEVICE_HAS_METHOD (stream, eol_cursor_width);
  258.   DEVICE_HAS_METHOD (stream, clear_to_window_end);
  259.   DEVICE_HAS_METHOD (stream, clear_region);
  260.   DEVICE_HAS_METHOD (stream, clear_frame);
  261.   DEVICE_HAS_METHOD (stream, output_begin);
  262.   DEVICE_HAS_METHOD (stream, output_end);
  263.   DEVICE_HAS_METHOD (stream, flash);
  264.   DEVICE_HAS_METHOD (stream, ring_bell);
  265. }
  266.  
  267. void
  268. vars_of_device_stream (void)
  269. {
  270.   DEFVAR_LISP ("terminal-device", &Vterminal_device,
  271.     "The initial device-object, which represent's Emacs's stdout.");
  272.   Vterminal_device = Qnil;
  273.  
  274.   DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
  275.     "The initial frame-object, which represents Emacs's stdout.");
  276.   Vterminal_frame = Qnil;
  277. }
  278.  
  279. void
  280. init_device_stream (void)
  281. {
  282.   /* This function can GC */
  283.   if (!initialized)
  284.     {
  285.       Vterminal_device = Fmake_device (Qstream, Qnil);
  286.       Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
  287.     }
  288.   else if (noninteractive)
  289.     event_stream_select_device (XDEVICE (Vterminal_device));
  290. }
  291.